﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YJKBuildingProfile.YJKBuildingProfile.Forms
{
	public partial class SettingForm : System.Windows.Forms.Form
	{
		public SettingForm(Autodesk.Revit.DB.Document doc)
		{
			this.m_Doc = doc;
			this.InitializeComponent();
		}

		private void SettingForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			for (int i = 0; i < 16; i++)
			{
				int num = i + 1;
				this.cmbLineWidth.Items.Add(num.ToString());
			}
			List<string> linePatternElementName = this.GetLinePatternElementName();
			foreach (string item in linePatternElementName)
			{
				this.cmbLinePatternName.Items.Add(item);
			}
			BuildingOutLineSettingInfo setting = SettingReaderWriter.GetSetting();
			this.cmbLineWidth.SelectedIndex = setting.LineWidth - 1;
			int num2 = linePatternElementName.FindIndex((string str) => str.CompareTo(setting.LinePatternName) == 0);
			if (num2 != -1)
			{
				this.cmbLinePatternName.SelectedIndex = num2;
				return;
			}
			this.cmbLinePatternName.SelectedIndex = 0;
		}

		private void SettingForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			SettingReaderWriter.SetSetting(new BuildingOutLineSettingInfo
			{
				LineWidth = this.cmbLineWidth.SelectedIndex + 1,
				LinePatternName = this.cmbLinePatternName.Text
			});
		}

		private List<string> GetLinePatternElementName()
		{
			IEnumerable<Element> enumerable = new FilteredElementCollector(this.m_Doc).OfClass(typeof(LinePatternElement)).ToElements();
			List<string> list = new List<string>();
			foreach (Element element in enumerable)
			{
				LinePatternElement linePatternElement = element as LinePatternElement;
				list.Add(linePatternElement.Name);
			}
			return list;
		}

		private Document m_Doc;
	}
}
